<?php
	//start the session
	session_start();

	//checks if user has logged in and if not displays an error message
	if(!isset($_SESSION['username']))
	{
		$_SESSION['message'] = "<span style='color: red; font-weight: bold;'>You are not logged in to view this page.</span>";
		header('Location: Login.php');
	}
?>

<!-- add_page.php view -->

<html>
	<head>
		<title>Add Favourite Page</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	
	<body>
		<div id="wrapper">
			<div id="banner"><img src="images/bannerv0.jpg" alt="header graphic"></div>
			<div id="wrapper_links"><?php include("menu/menu.php");?></div>			
			<div id="wrapper_body">

				<p align="left">User: <?php echo $_SESSION['username'];?></p>

				<h3>Add Page</h3>
		      
				<p> When entering the URL of a website do not include http://www.</p> 
					
				<center>
					<form class="" action="processes/record_bookmarks.php" method="POST">						
						<table>
							<tr>
								<td>Category:</td>
								<td>URL:</td>
								<td>Name:</td>
							</tr>
							
							<tr>
								<td>
									<select name="category">
								   
									<?php
										//defines file location
										$file = 'dropdown_data/dropdown_list.txt';
                                            
										//opens file
										$options = fopen($file, 'r');
								  
										//if the file is opened activate the while loop 
										if($options)
										{
											//tests for end-of-file
											while (!feof($options)) 
											{
												//gets the options located in the text file
												$line = fgets($options);

												$temp = explode(' |', $line);
												
												//outputs the options into the dropdown menu
												echo '<option name="' . $temp[0] . '" id="' . $temp[0] . '">' . $temp[0] . '</option>' . "<br />";
											}
   										
											fclose($options);
										}
									?>
						
									</select>
								</td>
								<td><input type="text" name="url" id="url" /></td>
								<td><input type="text" name="pageName" id="pageName" /></td>
							</tr>
						</table>
						<input type="submit" name="submit" id="submit" value="Submit" />
					</form> 
				</center>		     
		
				<?php
					//outputs the error/confirmation message from the record_bookmarks.php script on this page
					if(isset($_SESSION['message']))
					{
						echo $_SESSION['message'] . '<br />';
					}
				?>
					
            </div>
		</div>
    </body>
</html>